#!/bin/bash

# pnm2cjb2.sh 
# Combines all bitonal pnm files in the current directory into a bundled .djvu document
#
# (c) nabster
# Distribute under GPL
#
# Usage: ./pnm2cjb2.sh output_file_name_without_extension
#
echo
echo Converting all pnm files to temporary cjb2 files ending in .djvutemp
#########################################################################
# "filename" is the numbered file name without .pnm
for file in `ls *.pnm`
do
 filename=${file%.pnm}
 echo Converting $file
 cjb2 -losslevel 68 $file $filename.djvutemp
done
echo
echo Combing the files into a bundled document
##############################################
djvm -c $1.djvu `ls *.djvutemp`
echo
echo Displaying a copy for verification
#######################################
djview $1.djvu
echo
echo Removing the temporary files `ls *.djvutemp`
#################################################
rm *.djvutemp
echo
echo "The pnm files are not deleted just in case"
